{% extends '../admin_base/base.html' %}

{% block title %}<title>留言</title>{% end %}
{% block body %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
      <form action="" method="post">
        <h1 class="page-header">管理 <span class="badge">{{count}}</span></h1>
        <div class="table-responsive">
          <table class="table table-striped table-hover">
            <thead>
              <tr>
                <th><span class="glyphicon glyphicon-th-large"></span> <span class="visible-lg">选择</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">留言人</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">留言内容</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span class="visible-lg">手机</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span class="visible-lg">邮箱</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span class="visible-lg">时间</span></th>
                <th><span class="glyphicon glyphicon-pencil"></span> <span class="visible-lg">操作</span></th>
              </tr>
            </thead>
            <tbody>
            {%for contact in contacts%}
              <tr>
                <td><input type="checkbox" class="input-control" name="checkbox[]" value="" /></td>
                <td >{{contact.name}}</td>
                <td class="article-title">{{contact.content}}</td>
                <td >{{contact.mobile}}</td>
                <td >{{contact.email}}</td>
                <td >{{contact.create_time}}</td>
                <td><a rel="{{contact.id}}" name="see">查看</a> <a rel="{{contact.id}}" name="delete">删除</a></td>
              </tr>
            {% end %}
            </tbody>
          </table>
        </div>
      </form>
    </div>
  </div>
</section>
<div class="modal fade" id="seeContact" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" >查看留言</h4>
        </div>
        <div class="modal-body">
          <table class="table" style="margin-bottom:0px;">
            <thead>
              <tr> </tr>
            </thead>
            <tbody>
              <tr>
                <td wdith="20%">留言人</td>
                <td width="80%" class="see-contact-id"></td>
              </tr>
              <tr>
                <td wdith="20%">评论内容:</td>
                <td width="80%" class="see-contact-content"></td>
              </tr>
              <tr>
                <td wdith="20%">PHONE:</td>
                <td width="80%" class="see-contact-phone"></td>
              </tr>
              <tr>
                <td wdith="20%">所在地:</td>
                <td width="80%" class="see-contact-address"></td>
              </tr>
            </tbody>
            <tfoot>
              <tr></tr>
            </tfoot>
          </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">朕已阅</button>
        </div>
      </div>
  </div>
</div>

{% end %}
{% block end %}
<script>
$(function () {
    $("#main table tbody tr td a").click(function () {
        var name = $(this);
        var id = name.attr("rel"); //对应id
        if (name.attr("name") === "see") {
            $.ajax({
                type: "POST",
                url: "/admin/see_contact",
                data: "id=" + id,
                cache: false, //不缓存此页面
                success: function (data) {
                    $('.see-contact-id').html(data.data.name);
                    $('.see-contact-content').html(data.data.content);
                    $('.see-contact-phone').html(data.data.mobile);
                    $('.see-contact-address').html(data.data.address);
                    $('#seeContact').modal('show');
                }
            });
        } else if (name.attr("name") === "delete") {
            if (window.confirm("此操作不可逆，是否确认？")) {
                $.ajax({
                    type: "POST",
                    url: "/admin/delete_contact",
                    data: "id=" + id,
                    cache: false, //不缓存此页面
                    success: function (data) {
                        window.location.reload();
                    }
                });
            };
        };
        return false;
    });
});
</script>
{% end %}